module.exports = async(params) => {

    const {
        quickAppApi: {suggester},
        app,
        moment
    } = params;
    const path = require('path');
    const options_sourceFolder = ["wenjianjia","wenjianjia2"];
    const selected_oper = await suggester(options_sourceFolder,options_sourceFolder);
    let sourceFolder = "";
    if (!selected_oper) {
        sourceFolder = "morenwenjianjia"
        console.log(`用户取消选择，默认文件夹为${sourceFolder}`);
    } else {
        // 进处理此文件夹内的文件
        sourceFolder = selected_oper;
    }
    
    //过滤源文件夹内的文件列表
    const files = app.valut.getFiles().filter(file => {
        return file.path.startsWith(sourceFolder+'/');
    })

    const arr_targetFolder = ["mubiaowenjainjai","mubiaowenjianjia2"];
    const arr_status = ["done","waiting","pending","todo","doing"];

    for(let i = 0;i <arr_status.length;i++){
        let item_status = arr_status[i];
        let item_targetFolder = arr_targetFolder[i];
        let itemFiles =  files.filter(file=> {
            // 排除已在目标文件夹文件
            if (file.path.startsWith(item_targetFolder='/')){
                return false;
            }
            // 获取文件的元数据
            const metadata = app.metadataCache.getFileCache(file);
            // 根据状态过滤文件
            if(metadata && metadata.frontmatter){
                return metadata.frontmatter.status === item_status;
            }
            return false;
        });
        // 逐个移动文件到目标文件夹
        itemFiles.forEach(file=>{
            const metadata = app.metadataCache.getFileCache(file);
            if ( metadata && metadata.frontmatter ) {
                console.log(`File: ${file.path},status:${metadata.frontmatter}`);
            } else {
                console.log(`File:${file.path},no frontmatter or metadata`);
            }
            const targetPath = path.join(item_targetFolder,file.basename+'.'+file.extension);
            app.valut.rename(file,targetPath).then(()=>{
                new Notice(`${file.path}已移动到${item_targetFolder}文件夹`);
            }).catch(err => {
                new Notice(`移动${file.path}时出错`,err);
            });
        });
    }
    new Notice('文件移动完成');
}